<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL Diff</title>
    <style>

        body {
        }

        div.main {
            width:86%;
            margin: auto;
        }

        /* Padding and font style */
        table td, table th {
            padding: 5px 10px;
            font-size: 12px;
            font-family: Verdana;
            color: #5b7da3;
            text-align: left;
        }

        .table2 {
            width: 60%;
            border-collapse: collapse;
            border: 1px solid #a8bfde;
        }

        .table {
            width: 100%;
            border-collapse: collapse;
            border-bottom-width: 1px;
            border-bottom-style: solid;
            border-bottom-color: #a8bfde;
        }

        .table tr {
            border-bottom-width: 1px;
            border-bottom-style: dotted;
            border-bottom-color: #a8bfde;
        }

        /* Border styles */
        .table tr th {
            border-top-width: 1px;
            border-top-style: solid;
            border-top-color: #a8bfde;
            border-bottom-width: 1px;
            border-bottom-style: solid;
            border-bottom-color: #a8bfde;
        }

        /* Padding and font style */
        .table td, .table th {
            padding: 5px 10px;
            font-size: 12px;
            font-family: Verdana;
            color: #5b7da3;
            text-align: left;
        }


        .table .add {
            background: rgb(230, 238, 214)
        }

        .table .modify {
            background: rgb(223, 216, 232)
        }

        .table .drop {
            background: rgb(238, 211, 210)
        }

        /* Diff */
        .diff-mark {
            color: rgb(76, 11, 159);
            font-weight: bold;
            visibility: hidden;
            padding: 5px 0;
        }
        /* Tooltip 文本 */
        .diff-tooltip {
            visibility: hidden;
            width: 120px;
            background-color: #fba863;
            color: #fff;
            text-align: center;
            padding: 5px 0;
            border-radius: 6px;
            min-height: 10px;

            /* 定位 */
            position: absolute;
            z-index: 1;
        }

        /* 鼠标移动上去后显示提示框 */
        .table td.diff {
            color: #fba863;
            font-weight: bold;
        }
        .table td.diff:hover .diff-tooltip {
            visibility: visible;
        }





    </style>
</head>
<body>

<div class="main">
    <table class="table2">
        <tr>
            <th>so</th>
            <td th:text="${so_db}">${so_db}</td>
            <th>sn</th>
            <td th:text="${sn_db}">${sn_db}</td>
        </tr>
        <tr>
            <th>日期</th>
            <td th:text="${date}">${date}</td>
            <th>版本</th>
            <th th:text="${version}">${version}</th>
        </tr>
        <tr>
            <td colspan="4" th:text="${compareReporter}"></td>
        </tr>
    </table>
</div>
<br>
<br>

<div class="main">
    <h3>新增表</h3>
    <div class="new-table" th:each="tableChange : ${tableChanges}" th:if="${tableChange.tableDiff == null or tableChange.tableDiff.type eq 'CREATE'}">
        <h4 th:text="${tableChange.table.tableSchema}+'.'+${tableChange.table.tableName}"></h4>

        <h5>表信息</h5>
        <table class="table">
            <thead>
            <tr>
                <th width="20%">字符集</th>
                <th width="20%">排序规则</th>
                <th width="60%">注释</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td th:text="${tableChange.table.characterSetName}">utf-8</td>
                <td th:text="${tableChange.table.tableCollation}"></td>
                <td th:text="${tableChange.table.tableComment}"></td>
            </tr>
            </tbody>
        </table>


        <h5>字段</h5>
        <table class="table">
            <thead>
            <tr>
                <th width="10%">列名</th>
                <th width="10%">类型</th>
                <th width="10%">IS NULL</th>
                <th width="10%">默认值</th>
                <th width="10%">主键</th>
                <th width="30%">注释</th>
                <th width="30%">自增</th>
                <th width="20%">字符集</th>
                <th width="20%">排序规则</th>
                <th width="20%">EXTRA</th>
            </tr>
            </thead>

            <tbody>
            <tr th:each="column : ${tableChange.table.tableColumns}">
                <td th:text="${column.columnName}"></td>
                <td th:text="${column.columnType}"></td>
                <td th:text="${column.isNullable}"></td>
                <td th:text="${column.columnDefault}"></td>
                <td th:text="${column.columnKey}"></td>
                <td th:text="${column.columnComment}"></td>
                <td th:text="${column.autoIncr ? 'Y' : ''}"></td>
                <td th:text="${column.characterSetName}"></td>
                <td th:text="${column.collationName}"></td>
                <td th:text="${column.extra}"></td>
            </tr>
            </tbody>
        </table>

        <h5>索引</h5>
        <table class="table">
            <thead>
            <tr>
                <th width="10%">索引名称</th>
                <th width="10%">字段</th>
                <th width="10%">类型</th>
                <th width="10%">类型</th>
                <th width="10%">唯一索引</th>
            </tr>
            </thead>

            <tbody>
                <tr th:each="idx : ${tableChange.table.tableIndexes}">
                    <td th:text="${idx.indexName}"></td>
                    <td th:text="${idx.compositIndex}"></td>
                    <td th:text="${idx.indexType}"></td>
                    <td th:text="${idx.indexComment}"></td>
                    <td th:text="${idx.nonUnique == 0 ? 'Y' : ''}"></td>
                </tr>
            </tbody>
        </table>
        <br>
    </div>
</div>

<br><br>

<div class="main">

    <div class="change-table">
        <h3>修改表</h3>
        <div th:each="tableChange : ${tableChanges}" th:if="${tableChange.tableDiff != null and tableChange.tableDiff.type eq 'ALTER'}" >
            <h4 th:text="${tableChange.table.tableSchema}+'.'+${tableChange.table.tableName}"></h4>

            <h5>表信息</h5>
            <table class="table">
                <thead>
                <tr>
                    <th width="10%">字符集</th>
                    <th width="10%">排序规则</th>
                    <th width="60%">注释</th>
                </tr>
                </thead>
                <tbody>
                <tr th:object="${tableChange.tableDiff.nt}" th:with="ot = ${tableChange.tableDiff.ot}">
                    <td th:class="${ot.characterSetName} eq *{characterSetName} ? '' : 'diff'">
                        [[*{characterSetName}]]  <span class="diff-tooltip" th:text="${ot.characterSetName}"></span>
                    </td>
                    <td th:class="${ot.tableCollation} eq *{tableCollation} ? '' : 'diff'">[[*{tableCollation}]]   <span class="diff-tooltip" th:text="${ot.tableCollation}"></span></td>
                    <td th:class="${ot.tableComment} eq *{tableComment} ? '' : 'diff'">[[*{tableComment}]]   <span class="diff-tooltip" th:text="${ot.tableComment}"></span></td>
                </tr>
                <tr th:object="${tableChange.table}" th:if="${tableChange.tableDiff} == null">
                    <td>[[*{characterSetName}]]</td>
                    <td>[[*{tableCollation}]]</td>
                    <td>[[*{tableComment}]]</td>
                </tr>
                </tbody>
            </table>


            <h5>字段</h5>
            <table class="table">
                <thead>
                <tr>
                    <th width="10%">列名</th>
                    <th width="10%">类型</th>
                    <th width="10%">IS NULL</th>
                    <th width="10%">默认值</th>
                    <th width="10%">主键</th>
                    <th width="30%">注释</th>
                    <th width="30%">自增</th>
                    <th width="20%">字符集</th>
                    <th width="20%">排序规则</th>
                    <th width="20%">EXTRA</th>
                </tr>
                </thead>

                <tbody>
                <th:block th:each="diff : ${tableChange.columnDiffs}" th:switch="${diff.type}">
                    <tr th:case="'ADD'" th:with="column = ${diff.nt}" class="add">
                        <td th:text="${column.columnName}"></td>
                        <td th:text="${column.columnType}"></td>
                        <td th:text="${column.isNullable}"></td>
                        <td th:text="${column.columnDefault}"></td>
                        <td th:text="${column.columnKey}"></td>
                        <td th:text="${column.columnComment}"></td>
                        <td th:text="${column.autoIncr ? 'Y' : ''}"></td>
                        <td th:text="${column.characterSetName}"></td>
                        <td th:text="${column.collationName}"></td>
                        <td th:text="${column.extra}"></td>
                    </tr>
                    <tr th:case="'DROP'" th:with="column = ${diff.ot}" class="drop">
                        <td th:text="${column.columnName}"></td>
                        <td th:text="${column.columnType}"></td>
                        <td th:text="${column.isNullable}"></td>
                        <td th:text="${column.columnDefault}"></td>
                        <td th:text="${column.columnKey}"></td>
                        <td th:text="${column.columnComment}"></td>
                        <td th:text="${column.autoIncr ? 'Y' : ''}"></td>
                        <td th:text="${column.characterSetName}"></td>
                        <td th:text="${column.collationName}"></td>
                        <td th:text="${column.extra}"></td>
                    </tr>
                    <tr th:case="'MODIFY'" th:with="ot = ${diff.ot}, nt = ${diff.nt}" class="modify">
                        <td th:class="${nt.columnName != ot.columnName} ? 'diff' : ''" >[[${nt.columnName}]]<span class="diff-tooltip" th:text="${ot.columnName}"></span></td>
                        <td th:class="${nt.columnType != ot.columnType} ? 'diff' : ''">[[${nt.columnType}]]<span class="diff-tooltip" th:text="${ot.columnType}"></span></td>
                        <td th:class="${nt.isNullable != ot.isNullable} ? 'diff' : ''">[[${nt.isNullable}]]<span class="diff-tooltip" th:text="${ot.isNullable}"></span></td>
                        <td th:class="${nt.columnDefault != ot.columnDefault} ? 'diff' : ''">[[${nt.columnDefault}]]<span class="diff-tooltip" th:text="${ot.columnDefault}"></span></td>
                        <td th:class="${nt.columnKey != ot.columnKey} ? 'diff' : ''">[[${nt.columnKey}]]<span class="diff-tooltip" th:text="${ot.columnKey}"></span></td>
                        <td th:class="${nt.columnComment != ot.columnComment} ? 'diff' : ''">[[${nt.columnComment}]]<span class="diff-tooltip" th:text="${ot.columnComment}"></span></td>
                        <td th:class="${nt.autoIncr != ot.autoIncr} ? 'diff' : ''">[[${nt.autoIncr ? 'Y' : ''}]]<span class="diff-tooltip" th:text="${ot.autoIncr}"></span></td>
                        <td th:class="${nt.characterSetName != ot.characterSetName} ? 'diff' : ''">[[${nt.characterSetName}]]<span class="diff-tooltip" th:text="${ot.characterSetName}"></span></td>
                        <td th:class="${nt.collationName != ot.collationName} ? 'diff' : ''">[[${nt.collationName}]]<span class="diff-tooltip" th:text="${ot.collationName}"></span></td>
                        <td th:class="${nt.extra != ot.extra} ? 'diff' : ''">[[${nt.extra}]]<span class="diff-tooltip" th:text="${ot.extra}"></span></td>
                    </tr>
                    <tr th:case="*" th:with="ot = ${diff.ot}, nt = ${diff.nt}">
                        <td th:text="${nt.columnName}"></td>
                        <td th:text="${nt.columnType}"></td>
                        <td th:text="${nt.isNullable}"></td>
                        <td th:text="${nt.columnDefault}"></td>
                        <td th:text="${nt.columnKey}"></td>
                        <td th:text="${nt.columnComment}"></td>
                        <td th:text="${nt.autoIncr ? 'Y' : ''}"></td>
                        <td th:text="${nt.characterSetName}"></td>
                        <td th:text="${nt.collationName}"></td>
                        <td th:text="${nt.extra}"></td>
                    </tr>
                </th:block>
                </tbody>

            </table>

            <h5>索引</h5>
            <table class="table">
                <thead>
                <tr>
                    <th width="10%">索引名称</th>
                    <th width="10%">字段</th>
                    <th width="10%">类型</th>
                    <th width="10%">类型</th>
                    <th width="10%">唯一索引</th>
                </tr>
                </thead>

                <tbody>
                <th:block th:each="diff : ${tableChange.indexDiffs}" th:switch="${diff.type}">
                <tr th:case="'ADD'" th:with="idx = ${diff.nt}" class="add">
                    <td th:text="${idx.indexName}"></td>
                    <td th:text="${idx.compositIndex}"></td>
                    <td th:text="${idx.indexType}"></td>
                    <td th:text="${idx.indexComment}"></td>
                    <td th:text="${idx.nonUnique == 0 ? 'Y' : ''}"></td>
                </tr>
                <tr th:case="'DROP'" th:with="idx = ${diff.ot}" class="add">
                    <td th:text="${idx.indexName}"></td>
                    <td th:text="${idx.compositIndex}"></td>
                    <td th:text="${idx.indexType}"></td>
                    <td th:text="${idx.indexComment}"></td>
                    <td th:text="${idx.nonUnique == 0 ? 'Y' : ''}"></td>
                </tr>
                <tr th:case="'MODIFY'" th:with="nt = ${diff.nt}, ot = ${diff.ot}" class="modify">
                    <td th:class="${nt.indexName != ot.indexName} ? 'diff' : ''">[[${nt.indexName}]]<span class="diff-tooltip" th:text="${ot.indexName}"></span></td>
                    <td th:class="${nt.compositIndex != ot.compositIndex} ? 'diff' : ''">[[${nt.compositIndex}]]<span class="diff-tooltip" th:text="${ot.compositIndex}"></span></td>
                    <td th:class="${nt.indexType != ot.indexType} ? 'diff' : ''">[[${nt.indexType}]]<span class="diff-tooltip" th:text="${ot.indexType}"></span></td>
                    <td th:class="${nt.indexComment != ot.indexComment} ? 'diff' : ''">[[${nt.indexComment}]]<span class="diff-tooltip" th:text="${ot.indexComment}"></span></td>
                    <td th:class="${nt.nonUnique != ot.nonUnique} ? 'diff' : ''">[[${nt.nonUnique == 0 ? 'Y' : ''}]]<span class="diff-tooltip" th:text="${ot.nonUnique == 0 ? 'Y' : ''}"></span></td>
                </tr>
                <tr th:case="*" th:with="idx = ${diff.nt}">
                    <td th:text="${idx.indexName}"></td>
                    <td th:text="${idx.compositIndex}"></td>
                    <td th:text="${idx.indexType}"></td>
                    <td th:text="${idx.indexComment}"></td>
                    <td th:text="${idx.nonUnique == 0 ? 'Y' : ''}"></td>
                </tr>
                </th:block>
                </tbody>
            </table>
            <br>
        </div>

        </div>

</div>


</body>
</html>